/* Copyright (C) Abu Rizal, 2009.
 * 
 * This file is part of QurText.
 * 
 * QurText is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * QurText is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with QurText. If not, see <http://www.gnu.org/licenses/>.
 */
package qurtext.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;

public class HeaderView extends BaseView {
	private final Label userLabel=new Label("Guest");
	private final Hyperlink loginLink=new Hyperlink("Log in","");
	private final HorizontalPanel loginBar = new HorizontalPanel();
	private final Label userProgressLabel=new Label("");
	private UserPresenter userPresenter;

	public UserPresenter getUserPresenter() {
		return userPresenter;
	}
	public void setUserPresenter(UserPresenter userPresenter) {
		this.userPresenter = userPresenter;
	}
	public void setUserText(String userText) {
		userLabel.setText(userText);
	}
	public void setLoginLinkText(String loginLinkText) {
		loginLink.setText(loginLinkText);
	}
	public void setLoginLinkHint(String loginLinkHint) {
		loginLink.setTitle(loginLinkHint);
	}
	public void onHeaderViewLoad() {
		userProgressLabel.setTitle("Click to reset");
		userProgressLabel.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				if (Window.confirm("Are you sure to reset your progress to 0.0%?")) {
					userPresenter.resetUserProgress();
				};
			}
			
		});
		userProgressLabel.addStyleName("clickable");
	    loginBar.add(userProgressLabel);
	    loginBar.add(spacer());
		loginBar.add(userLabel);
	    loginBar.add(spacer());
	    loginBar.add(loginLink);

	    RootPanel.get("logindiv").add(loginBar);
	    
	    loginLink.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				userPresenter.onLoginLinkClick();
			}
	    	
	    });
	    
	    
	}
	public void setUserProgressText(String userProgressText) {
		userProgressLabel.setText(userProgressText);
	}

	
}
